package com.commons;

/**
 * Class defined as wrapper which holds key value pair of object as 
 * in form of object elements in string for.<br/>
 * 
 * Object is mainly used in those list where instance of key value pair are required
 * list in ww:select or s:select, checkboxlist, radio etc.
 * 
 * @author uday.kumar
 */
public class ListFieldWrapper {
	
	/**
	 * Represents the display name of list field selection component   
	 */
	private String fieldText;
	
	/**
	 * Represents the display name of list field selection component   
	 */
	private String fieldName;
	
	/**
	 * Represents the Value of list field selection component
	 */
	private String fieldValue;
	
	/**
	 * default constructor
	 */
	public ListFieldWrapper(){
	}
	
	/**
	 * single argumented object intializer which will set both values (text and value)
	 * @param field - text(options) displayed in list and value associated with text 
	 */
	public ListFieldWrapper(String field){
		this.fieldText = field;
		this.fieldName = field;
		this.fieldValue = field;
	}
	
	/**
	 * All argumented object intializer
	 * @param fieldText - text(options) displayed in list 
	 * @param fieldValue - value associated with text
	 */
	public ListFieldWrapper(String fieldText,String fieldValue){
		this.fieldText = fieldText;
		this.fieldName =  fieldText;
		this.fieldValue = fieldValue;
	}
	
	public ListFieldWrapper(String fieldText,String fieldName,String fieldValue){
		this.fieldText = fieldText;
		this.fieldName =  fieldName;
		this.fieldValue = fieldValue;
	}
	/**
	 * Returns a string representation of the object.
	 * 
	 * @return textual representation 
	 */
	@Override
	public String toString() {
		return  "TEXT: "+ fieldText+", VALUE: "+fieldValue;
	}
	
	/**
	 * Indicates whether some other object is "equal to" this one.<br/>
	 * With instance of current object, if <code>fieldText</code> & <code>fieldValue</code>
	 * contains same String as in comparing element then instance are stated as equal 
	 * 
	 * @param obj - compairision element
	 * @return true if object elements contains same string
	 */
	@Override
	public boolean equals(Object obj) {
		boolean result = false;
		if (obj instanceof ListFieldWrapper) {
			ListFieldWrapper lfw = (ListFieldWrapper) obj;
			result = ((this.fieldText.equals(lfw.fieldText)) && (this.fieldValue.equals(lfw.fieldValue))&& (this.fieldName.equals(lfw.fieldName)));
		}
		return result; 	 
	}

	/**
	 * @return fieldValue - value associated with text
	 */
	public String getFieldValue() {
		return fieldValue;
	}

	/**
	 * @param fieldValue - value associated with text
	 */
	public void setFieldValue(final String fieldValue) {
		this.fieldValue = fieldValue;
	}
	
	/**
	 * @return the fieldName - text(options) displayed in list 
	 */
	public String getFieldName() {
		return fieldName;
	}

	/**
	 * @param fieldName the fieldName to set
	 */
	public void setFieldName(final String fieldName) {
		this.fieldName = fieldName;
		//this.fieldText = fieldName;
	}

	/**
	 * @return the fieldText - text(options) displayed in list 
	 */
	public String getFieldText() {
		return fieldText;
	}

	/**
	 * @param fieldText the fieldText to set
	 */
	public void setFieldText(final String fieldText) {
		this.fieldText = fieldText;
		this.fieldName = fieldText;
	}

}
